<?php
class MobileInterceptor extends Interceptor 
{
    public function before($context) 
    {/*{{{*/
        $uri = getenv('REQUEST_URI');

        if (false == stripos($uri, 'clkfrom=ios') && false == stripos($uri, 'clkfrom=and'))
        {
            $agent = getenv('HTTP_USER_AGENT');
            $_COOKIE['mbi'] = isset($_COOKIE['mbi'])?$_COOKIE['mbi']:'';
            if (empty($_COOKIE['mbi']) 
                && (false !== stripos($agent, 'iphone') 
                    || false !== stripos($agent, 'ios')
                    || false !== stripos($agent, 'ipod')))
            {
                $url = 'http://'.getenv('HTTP_HOST').$uri;
                $context->response->exitJump('http://www.'.URL_PREFIX.'haodf.com/index/mobileredirect?type=ios&url='.rawurlencode($url));
            }
            elseif (empty($_COOKIE['mbi']) && (false !== stripos($agent, 'Android') || false !== stripos($agent, 'Adr')))
            {
                $url = 'http://'.getenv('HTTP_HOST').$uri;
                $context->response->exitJump('http://www.'.URL_PREFIX.'haodf.com/index/mobileredirect?type=and&url='.rawurlencode($url));
            }
            elseif (empty($_COOKIE['mbi']) && false !== stripos($agent, 'Firefox/1.0.7'))
            {
                $url = 'http://'.getenv('HTTP_HOST').$uri;
                $context->response->exitJump('http://www.'.URL_PREFIX.'haodf.com/index/mobileredirect?type=uc&url='.rawurlencode($url));
            }
        }
    }/*}}}*/

    public function after($context) 
    {
    }
}
